package cn.appsys.service.developer.AppVersion;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.appsys.dao.developer.AppInfo.AppInfoMapper;
import cn.appsys.dao.developer.AppVersion.AppVersionMapper;
import cn.appsys.pojo.AppVersion;

@Controller
@Transactional
public class AppVersionServiceImpl implements AppVersionService {
	
	@Resource
	AppVersionMapper appVersionMapper;
	@Resource
	AppInfoMapper appInfoMapper;
	
	@Override
	public List<AppVersion> appVersionList(Integer appId) {
		// TODO Auto-generated method stub
		return appVersionMapper.getAppVersionList(appId);
	}
	/**
	 * 业务：新增app的版本信息
	 * 1、app_verion表插入数据
	 * 2、更新app_info表对应app的versionId字段（记录最新版本id）
	 * 注意：事务控制
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean appsysadd(AppVersion appVersion) throws Exception {
		// TODO Auto-generated method stub
		boolean flag = false;
		Integer versionId = null;
		if(appVersionMapper.getAppVersionadd(appVersion) > 0){
			versionId = appVersion.getId();
			flag = true;
		}
		if(appInfoMapper.getupdateVersionId(versionId, appVersion.getAppId()) > 0 && flag){
			flag = true;
		}
		return flag;
	}
	@Override
	public AppVersion appVersionById(Integer id) {
		// TODO Auto-generated method stub
		return appVersionMapper.getAppVersionById(id);
	}
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean appVersionFileDel(Integer id) {
		// TODO Auto-generated method stub
		boolean YesNo = false;
		int result = appVersionMapper.getAppVersionFileDel(id);
		if(result == 1){
			YesNo = true;
		}
		return YesNo;
	}
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean appVersionmodify(AppVersion appVersion) {
		// TODO Auto-generated method stub
		boolean YesNo = false;
		int result = appVersionMapper.getAppVersionmodify(appVersion);
		if(result == 1){
			YesNo = true;
		}
		return YesNo;
	}
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean appVersiondel(Integer id) {
		// TODO Auto-generated method stub
		boolean YesNo = false;
		int result = appVersionMapper.getAppVersiondel(id);
		if(result == 1){
			YesNo = true;
		}
		return YesNo;
	}

}
